package com.ft.scan.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;
import java.util.List;

/**
 * Swagger2配置信息
 * 也可以根据实际情况来减少或者增加组
 *
 * @author 悟解
 * {@code @date} 2024-1-30
 */
@Configuration
@EnableSwagger2WebMvc
public class Swagger2Config {

    private ApiInfo webApiInfo() {
        return new ApiInfoBuilder()
                .title("悟解的API文档")
                .description("本文档整合Knife4j才得到")
                .version("1.0")
                .contact(new Contact("悟解",
                        "https://blog.csdn.net/liyankang",
                        "liyankang@aliyun.com"))
                .build();
    }

    @Bean
    public Docket userApiConfig() {
        List<Parameter> pars = new ArrayList<>();
        ParameterBuilder tokenPar = new ParameterBuilder();
        tokenPar.name("用户管理接口")
                .required(false)
                .build();
        pars.add(tokenPar.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("用户端接口")
                .apiInfo(webApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ft.scan"))
                .paths(PathSelectors.ant("/ft/**"))  // 修改路径筛选条件
                .build()
                .globalOperationParameters(pars);
    }


}


